﻿using System.Collections.ObjectModel;
using Domain.Abstract;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.Entity;

namespace Domain.Concrete
{
    public class NccRepository : INccRepository
    {
        private readonly NCCEntities _context = new NCCEntities();

        public IQueryable<Ncc> Nccs
        {
            get { return _context.Nccs; }
        }

        public BusinessObjects.NccDto GetNccById(int id)
        {
            //return _context.Nccs.Include(x=> x.NoiCapTLinh.QuanHuyen)
            //                    .Include(x => x.NhomNcc)
            //                    .FirstOrDefault(n => n.Id == id);

            return _context.Nccs.Where(x => x.Id == id)
                .Select(x => new BusinessObjects.NccDto
                                 {
                                     HoTen = x.HoTen,
                                     NamSinh = x.NamSinh,
                                     GioiTinh = x.GioiTinh,
                                     NoiCapTruyLinh = x.NoiCapTruyLinh,
                                     NguyenQuan = x.NguyenQuan,
                                     NhomNcc = x.NhomNcc.Select(nh => new BusinessObjects.NhomNccDto { Ten = nh.Ten })
                                 })
                .FirstOrDefault();
        }
    }
}
